﻿using System;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpriteGame.Rendering;
using System.Collections.Generic;

namespace SpriteGame.Entities
{
    class BreakableShape:BaseSprite
    {
        public BreakableShape(World _world, float _width, float _height, BodyType _type, Vector2 _position, String _texture)
        {
            texture = "Textures/rock";
            world = _world;

            Texture2D polygonTexture = TextureLibrary.GetTexture("Textures/rock");

            width = polygonTexture.Width * 0.1f;
            height = polygonTexture.Height * 0.1f;

            uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];

            polygonTexture.GetData(data);

            Vertices verts = PolygonTools.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height);
            Vector2 scale = new Vector2(0.07f, 0.07f);
            verts.Scale(ref scale);

            //FixtureFactory.CreateBreakableBody(world, verts, 50, new Vector2(-10, 25));

            //body.
            //width = _width;
            //height = _height;

            //float r = width * 0.5f;

            //CircleShape shape = new CircleShape(r);

            PolygonShape shape = new PolygonShape(verts);

            

            body = world.CreateBody();
            body.FixtureList.Add(FixtureFactory.CreatePolygon(world, verts, 0.5f));
            body.SetTransform(ref _position, 0.0f);
            body.BodyType = _type;

            //List<Fixture> capsule = FixtureFactory.CreateCapsule(world, 10, 2,
            //                                         (int)MathHelper.Max(3, 1), 3,
            //                                         (int)MathHelper.Max(3, 1), 10,
            //                                         _position);
            //body = capsule[0].Body;
            //body.SetTransform(_position, 0.0f);
            //capsule[0].Body.BodyType = BodyType.Dynamic;

            //Fixture fixture = body.CreateFixture(shape);
            //fixture.Restitution = 0.2f;

            //body.IsBullet = true;

            //body.UserData = this;
        }
    }
}
